home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / colorcal.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  8.0 KB  |  227 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '3.0'
  5. __title__ = 'Printer Cartridge Color Calibration Utility'
  6. __mod__ = 'hp-colorcal'
  7. __doc__ = 'Perform color calibration on HPLIP supported inkjet printers. (Note: Not all printers require the use of this utility).'
  8. import sys
  9. import re
  10. import getopt
  11. import operator
  12. import os
  13. from base.g import *
  14. from base import device, status, utils, maint, tui, module
  15. from prnt import cups
  16.  
  17. def enterAlignmentNumber(letter, hortvert, colors, minimum, maximum):
  18.     return tui.enter_range('Enter the best aligned value for line %s (%d-%d or q=quit): ' % (letter, minimum, maximum), minimum, maximum)
  19.  
  20.  
  21. def enterPaperEdge(maximum):
  22.     return tui.enter_range('Enter numbered arrow that is best aligned with the paper edge (1-%d or q=quit): ' % maximum, 1, maximum)
  23.  
  24.  
  25. def colorAdj(line, maximum):
  26.     return tui.enter_range('Enter the numbered box on line %s that is best color matched to the background color (1-%d or q=quit): ' % (line, maximum), 1, maximum)
  27.  
  28.  
  29. def colorCal():
  30.     return tui.enter_range('Enter the numbered image labeled "1" thru "7" that is best color matched to the image labeled "X', 1, 7)
  31.  
  32.  
  33. def colorCal2():
  34.     return tui.enter_range('Select the number between 1 and 81 of the numbered patch that best matches the background.', 1, 81)
  35.  
  36.  
  37. def invalidPen():
  38.     log.error('Invalid cartridge(s) installed.\nPlease install valid cartridges and try again.')
  39.  
  40.  
  41. def photoPenRequired():
  42.     log.error('Photo cartridge not installed.\nPlease install the photo cartridge and try again.')
  43.  
  44.  
  45. def photoPenRequired2():
  46.     log.error('Photo cartridge or photo blue cartridge not installed.\nPlease install the photo (or photo blue) cartridge and try again.')
  47.  
  48.  
  49. def colorCal4():
  50.     log.info("Instructions:\n1. Hold the calibration page at arm's length in front of your eyes.\n2. Tilt the page away from you. Look at the two large squares, each containing colored patches. For each large square, find the colored path that most closely matches the background color. Each patch has an associated letter and number.\n")
  51.     values = [
  52.         0,
  53.         0,
  54.         0,
  55.         0]
  56.     ok = True
  57.     while True:
  58.         x = raw_input(log.bold('Enter the letter (\'A\' thru \'N\') and number (1 thru 14) for the GRAY plot (eg, "C5") or "q" to quit: '))
  59.         if x.lower().strip() == 'q':
  60.             ok = False
  61.             break
  62.         
  63.         if x.lower().strip() == 'd':
  64.             (values[0], values[1]) = (-1, -1)
  65.             break
  66.         
  67.         if len(x) < 2:
  68.             log.error('You must enter at least two characters (a letter and a number)')
  69.             continue
  70.         
  71.         if len(x) > 3:
  72.             log.error('Enter only a single letter and a one or two digit number (eg, "C5").')
  73.             continue
  74.         
  75.         letter = x[0].lower()
  76.         if letter not in 'abcdefghijklmn':
  77.             log.error("You must enter a letter 'A' thru 'N'")
  78.             continue
  79.         
  80.         
  81.         try:
  82.             number = int(x[1:])
  83.         except ValueError:
  84.             log.error("You must enter a letter 'A' thru 'N' followed by a number 1 thru 14.")
  85.             continue
  86.  
  87.         if number < 0 or number > 14:
  88.             log.error("You must enter a letter 'A' thru 'N' followed by a number 1 thru 14.")
  89.             continue
  90.         
  91.         values[0] = ord(str(letter).upper()) - ord('A')
  92.         values[1] = number - 1
  93.         break
  94.     if ok:
  95.         while True:
  96.             x = raw_input(log.bold('Enter the letter (\'P\' thru \'V\') and number (1 thru 7) for the COLOR plot (eg, "R3") or "q" to quit: '))
  97.             if x.lower().strip() == 'q':
  98.                 ok = False
  99.                 break
  100.             
  101.             if x.lower().strip() == 'd':
  102.                 (values[2], values[3]) = (-1, -1)
  103.                 break
  104.             
  105.             if len(x) < 2:
  106.                 log.error('You must enter at least two characters (a letter and a number)')
  107.                 continue
  108.             
  109.             if len(x) > 3:
  110.                 log.error('Enter only a single letter and a one or two digit number (eg, "R3").')
  111.                 continue
  112.             
  113.             letter = x[0].lower()
  114.             if letter not in 'pqrstuv':
  115.                 log.error("You must enter a letter 'P' thru 'V'")
  116.                 continue
  117.             
  118.             
  119.             try:
  120.                 number = int(x[1:])
  121.             except ValueError:
  122.                 log.error("You must enter a letter 'P' thru 'V' followed by a number 1 thru 7.")
  123.                 continue
  124.  
  125.             if number < 0 or number > 7:
  126.                 log.error("You must enter a letter 'P' thru 'V' followed by a number 1 thru 7.")
  127.                 continue
  128.             
  129.             values[2] = ord(str(letter).upper()) - ord('P')
  130.             values[3] = number - 1
  131.             break
  132.     
  133.     return (ok, values)
  134.  
  135.  
  136. try:
  137.     mod = module.Module(__mod__, __title__, __version__, __doc__, None, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT4,))
  138.     mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS, see_also_list = [
  139.         'hp-align',
  140.         'hp-clean',
  141.         'hp-linefeedcal',
  142.         'hp-pqdiag'])
  143.     (opts, device_uri, printer_name, mode, ui_toolkit, lang) = mod.parseStdOpts()
  144.     device_uri = mod.getDeviceUri(device_uri, printer_name, filter = {
  145.         'color-cal-type': (operator.ne, COLOR_CAL_TYPE_NONE) })
  146.     if mode == GUI_MODE:
  147.         if not utils.canEnterGUIMode4():
  148.             log.error('%s -u/--gui requires Qt4 GUI support. Entering interactive mode.' % __mod__)
  149.             mode = INTERACTIVE_MODE
  150.         
  151.     
  152.     if mode == INTERACTIVE_MODE:
  153.         
  154.         try:
  155.             d = device.Device(device_uri, printer_name)
  156.         except Error:
  157.             e = None
  158.             log.error('Unable to open device: %s' % e.msg)
  159.             sys.exit(1)
  160.  
  161.         
  162.         try:
  163.             d.open()
  164.         except Error:
  165.             log.error('Unable to print to printer. Please check device and try again.')
  166.             sys.exit(1)
  167.         
  168.  
  169.         if d.isIdleAndNoError():
  170.             color_cal_type = d.mq.get('color-cal-type', COLOR_CAL_TYPE_NONE)
  171.             log.debug('Color calibration type=%d' % color_cal_type)
  172.             if color_cal_type == COLOR_CAL_TYPE_UNSUPPORTED:
  173.                 log.error("Color calibration through HPLIP not supported for this printer. Please use the printer's front panel to perform color calibration.")
  174.             elif color_cal_type == COLOR_CAL_TYPE_DESKJET_450:
  175.                 maint.colorCalType1(d, tui.load_paper_prompt, colorCal, photoPenRequired)
  176.             elif color_cal_type == COLOR_CAL_TYPE_MALIBU_CRICK:
  177.                 maint.colorCalType2(d, tui.load_paper_prompt, colorCal2, invalidPen)
  178.             elif color_cal_type == COLOR_CAL_TYPE_STRINGRAY_LONGBOW_TORNADO:
  179.                 maint.colorCalType3(d, tui.load_paper_prompt, colorAdj, photoPenRequired2)
  180.             elif color_cal_type == COLOR_CAL_TYPE_CONNERY:
  181.                 maint.colorCalType4(d, tui.load_paper_prompt, colorCal4, None)
  182.             elif color_cal_type == COLOR_CAL_TYPE_COUSTEAU:
  183.                 maint.colorCalType5(d, tui.load_paper_prompt)
  184.             elif color_cal_type == COLOR_CAL_TYPE_CARRIER:
  185.                 maint.colorCalType6(d, tui.load_paper_prompt)
  186.             elif color_cal_type == COLOR_CAL_TYPE_TYPHOON:
  187.                 maint.colorCalType7(d, tui.load_photo_paper_prompt)
  188.             else:
  189.                 log.error('Invalid color calibration type.')
  190.         else:
  191.             log.error('Device is busy or in an error state. Please check device and try again.')
  192.             sys.exit(1)
  193.         d.close()
  194.     else:
  195.         
  196.         try:
  197.             from PyQt4.QtGui import QApplication
  198.             from ui4.colorcaldialog import ColorCalDialog
  199.         except ImportError:
  200.             d.isIdleAndNoError()
  201.             d.isIdleAndNoError()
  202.             log.error('Unable to load Qt4 support. Is it installed?')
  203.             sys.exit(1)
  204.         except:
  205.             d.isIdleAndNoError()
  206.  
  207.         app = QApplication(sys.argv)
  208.         dlg = ColorCalDialog(None, device_uri)
  209.         dlg.show()
  210.         
  211.         try:
  212.             log.debug('Starting GUI loop...')
  213.             app.exec_()
  214.         except KeyboardInterrupt:
  215.             d.isIdleAndNoError()
  216.             d.isIdleAndNoError()
  217.             sys.exit(0)
  218.         except:
  219.             d.isIdleAndNoError()
  220.  
  221.         sys.exit(0)
  222. except KeyboardInterrupt:
  223.     log.error('User exit')
  224.  
  225. log.info('')
  226. log.info('Done.')
  227.